package com.chixing.controller;

import com.chixing.service.SightsCollectionService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class SightsCollectionConreoller {

    @Autowired
    private SightsCollectionService sightsCollectionService;
//    @GetMapping("/customer_collection/{custId}")
//
//    public ModelAndView getSightsbycustId(@PathVariable("custId") Integer custId ){
//        ServerResponse response=sightsCollectionService.getSightsbycustId(custId);
//        ModelAndView mav = new ModelAndView();
//        mav.addObject("response",response);
//        mav.setViewName("customer/customer_collection");
//        return mav;
//    }

    @GetMapping(value={"/customer_collection/{custId}","/customer_collection/{custId}/page/{pageNum}"})

    public ModelAndView getSightsbycustId(@PathVariable("custId") Integer custId ,
                                          @PathVariable(value = "pageNum",required = false)Integer pageNum){
        if(pageNum == null)
            pageNum = 1;
        ServerResponse response=sightsCollectionService.getSightsbycustId(custId);
        ModelAndView mav = new ModelAndView();
        ServerResponse serverResponse=sightsCollectionService.getByCustIdAndPage(custId,pageNum);
        mav.addObject("response",response);
        mav.setViewName("customer/customer_collection");
        return mav;
    }




}
